package date;

import java.text.SimpleDateFormat;
import java.time.*;
import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.Date;

public class LocalDateTest {

    //LocalDate：年月日
    //LocalTime：时分秒
    //LocalDateTime：年月日时分秒
    public static void main(String[] args) {
        //2021-05-23T23:59:59.999999999
        //2021-05-23T00:00
        LocalDate findDate1 = LocalDate.parse("2021-05-23");
        System.out.println(findDate1);
        LocalDateTime searStart = LocalDateTime.of(findDate1, LocalTime.MIN);
        LocalDateTime searEnd = LocalDateTime.of(findDate1, LocalTime.MAX);
        System.out.println(searEnd);
        System.out.println(searStart);

        //Calendar直接输出的都不是数值时间
        // 使用默认时区和语言环境获得一个日历
        Calendar cal = Calendar.getInstance();
        System.out.println("+++++++++"+cal);
        // 赋值时年月日时分秒常用的6个值，注意月份下标从0开始，所以取月份要+1
        System.out.println("年:" + cal.get(Calendar.YEAR));
        System.out.println("月:" + (cal.get(Calendar.MONTH) + 1));
        System.out.println("日:" + cal.get(Calendar.DAY_OF_MONTH));
        System.out.println("时:" + cal.get(Calendar.HOUR_OF_DAY));
        System.out.println("分:" + cal.get(Calendar.MINUTE));
        System.out.println("秒:" + cal.get(Calendar.SECOND));

        Date date = new Date();
        //Tue Jun 22 11:30:05 CST 2021格式时间不方便阅读
        System.out.println(date);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(simpleDateFormat.format(date));

        LocalDate findDate = LocalDate.parse("2021-05-26");
        System.out.println(findDate);
        LocalDate localDate = LocalDate.now();
        //构造指定的年月日
        LocalDate localDate1 = LocalDate.of(2019, 9, 10);
        //2019-09-10
        System.out.println(localDate1);

        //获取年、月、日、星期几,获取CST格式时间和int类型时间
        int year = localDate.getYear();
        System.out.println(year);
        int year1 = localDate.get(ChronoField.YEAR);
        System.out.println(year1);
        Month month = localDate.getMonth();
        System.out.println(month);
        int month1 = localDate.get(ChronoField.MONTH_OF_YEAR);
        System.out.println(month1);
        int day = localDate.getDayOfMonth();
        System.out.println(day);
        int day1 = localDate.get(ChronoField.DAY_OF_MONTH);
        System.out.println(day1);

//        TUESDAY
//        2
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        System.out.println(dayOfWeek);
        int dayOfWeek1 = localDate.get(ChronoField.DAY_OF_WEEK);
        System.out.println(dayOfWeek1);
    }
}
